#include <iostream>
#include <algorithm>

#define f(x,l,r) for (int x = l; x <= r; ++ x)

using namespace std;

const int N = 40;

int n;
int w[N];
int f[N][N], g[N][N];

void dfs(int l, int r) {
    if (l > r) return;
    int t = g[l][r];
    cout << t << ' ';
    dfs(l, t - 1);
    dfs(t + 1, r);
}

int main() {
    cin >> n;
    
    f(i, 1, n) cin >> w[i];
    
    f(len, 1, n) 
        f(l, 1, n + 1 - len) {
            int r = l + len - 1;
            if (l == r) {
                f[l][r] = w[l];
                g[l][r] = l;
            }
            else {
               f(k, l, r) {
                   int left = k == l ? 1 : f[l][k - 1];
                   int right = k == r ? 1 :f[k + 1][r];
                   int score = left * right + w[k];
                   if (score > f[l][r]) {
                       f[l][r] = score;
                       g[l][r] = k;
                   }
               }
            }
        }
    
    cout << f[1][n] << endl;
    dfs(1, n);
    
    return 0;
}